wx.cloud.init()
const db = wx.cloud.database({});
Page({
  data: {
    chooseTitle: '选择一张图片',
    hasPic: false,
    tempFilePaths: '',
    isGetInfo: false,
    width: 0,
    height: 0,
    orientation: '',
    type: '',
    compressQuality: 80,
    showPath: '',
    text1:'',
    text2:'',
    text3:''
  },

  chooseImg () {
    let that = this
    wx.chooseImage({
      count: 1,
      success: function (res) {
        console.log(res)
        let path = res.tempFilePaths
        that.setData({
          chooseTitle: '更换一张图片',
          hasPic: true,
          tempFilePaths: path,
          showPath: path
        })
      },
      fail: function (e) {
        wx.showToast({
          title: "出错了T_T，请重新上传", // 提示的内容
          icon: "none", // 图标，默认success
          duration: 1500, // 提示的延迟时间，默认1500
          mask: false, // 是否显示透明蒙层，防止触摸穿
      })
        console.log('选择图片失败', e)
      }
    })
  },


  preview () {
    let that = this
    wx.previewImage({
      urls: [that.data.showPath]
    })
  },

  saveImg () {
    let that = this
    wx.saveImageToPhotosAlbum({
      filePath: that.data.showPath
    })
  },



btnSub(res){
  var that =this
  console.log(this.data.showPath)
  wx.showLoading({
    title: '数据提交中......',
  })
  var {name,loc,note,src}=res.detail.value;
  console.log(name,loc,note)
  //var resVlu=res.detail.value
  if(this.data.showPath.length=="0"||name==""||loc==""||note==""){
    wx.showToast({
      title: "数据不能为空哦^_^",
      icon: "none",
      duration: 1500,
      mask: false,
    })
  }
  else{
  console.log(name,loc,note,src)
  db.collection("items").add({
    data:{
      name:name,
      loc:loc,
      note:note,
      src:that.data.tempFilePaths        
    } 
  }).then(res=>{
    console.log(res)
    console.log(name)
      wx.hideLoading({
      success: (res) => {},
    })
    wx.showToast({
        title: "成功", // 提示的内容
        icon: "success", // 图标，默认success
        duration: 1500, // 提示的延迟时间，默认1500
        mask: false, // 是否显示透明蒙层，防止触摸穿
    })
    that.setData({
        text1:'',
        text2:'',
        text3:'',
        hasPic: false,
    })
  })
 }
},
function(){
  $.fn.autoHeight = function(){    
  function autoHeight(elem){
      elem.style.height = 'auto';
      elem.scrollTop = 0; //防抖动
      elem.style.height = elem.scrollHeight + 'px';
  }
  this.each(function(){
      autoHeight(this);
      $(this).on('keyup', function(){
          autoHeight(this);
      });
  });     
}                
('textarea[autoHeight]').autoHeight();    
},

//点击查看物品跳转页面
chackItem:function(){
  wx.switchTab({
    url: '../chackItem/chackItem',
  })
},

})


